、<template>
  <div class="app-container search-table-box aidex-table">
    <el-card shadow="never" ref="queryRef" style="margin-bottom: 12px;" class="search_card" v-show="showSearch">
      <div class="filter-container">
        <div class="search_box">
          <el-form :model="queryParams" ref="queryForm" label-width="80px">
            <el-row :gutter="16">
              <el-col :md="6" >
                <el-form-item label="公告标题" prop="title">
                  <el-input
                    v-model="queryParams.title"
                    placeholder="请输入公告标题"
                    clearable
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
              </el-col>
              <el-col :md="6" align="right" style="float: right;">
                <el-form-item>
                  <el-button class="filter-item" type="primary" @click="handleQuery">搜索</el-button>
                  <el-button class="filter-item" style="margin-left: 8px" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
    </el-card>
    <el-card shadow="never" >
      <template #header>
        <el-row>
          <el-col :span="8">
            <div class="card-header">
              <el-button disabled type="text">公告栏信息</el-button>
            </div>
          </el-col>
          <el-col :span="16">
            <div class="btn_box" align="right" style="float: right;">
              <el-button
                type="danger"
                icon="el-icon-delete"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['system:bulletin:remove']"
              >批量删除</el-button>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </div>
          </el-col>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="bulletinList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="公告标题" align="center" prop="title" width="150" show-overflow-tooltip/>
        <el-table-column label="公告内容" align="center" prop="content" width="260" show-overflow-tooltip/>
        <el-table-column label="接收人员" align="center" prop="reciveStaffNames" show-overflow-tooltip />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发送时间" align="center" prop="sendTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.sendTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"           
              @click="showInfo(scope.row)"
              v-hasPermi="['system:bulletin:info']"
            >查看</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:bulletin:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <bulletin-info :info="currInfo" ref="bulletinInfo"></bulletin-info>
  </div>
</template>

<script>
import { listBulletin, delBulletin } from "@/api/system/bulletin";
import BulletinInfo from './common/bulletinInfo.vue';
export default {
  name: "Bulletin",
  components: {BulletinInfo},
  data() {
    return {
      currInfo: {},
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      single: true,
      // 非多个禁用
      multiple: true,
      // 公告栏表格数据
      bulletinList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      innerOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sts: 'A',
        title: null,
        createUserId: null,
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公告栏列表 */
    getList() {
      this.loading = true;
      listBulletin(this.queryParams).then(response => {
        this.bulletinList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(ex => {
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.bulletinId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    showInfo (row) {
      this.currInfo = row
      this.$refs['bulletinInfo'].show()
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const bulletinIds = row.bulletinId || this.ids;
      this.$modal.confirm('是否确认删除选中的数据项？').then(function() {
        return delBulletin(bulletinIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
}
</script>